package com.xw.converter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xw.entity.ReserveItem;
import com.xw.enums.ResultEnum;
import com.xw.exception.YdException;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: y
 * @CreateDate: 9/15/21 4:15 PM
 * @Version: 1.0
 */
@Slf4j
public class UserStr2UserListDTO {

    public static List<ReserveItem> convert(String userStr) {
        Gson gson = new Gson();

        List<ReserveItem> reserveItemArrayList = new ArrayList<>();

        try {
            reserveItemArrayList = gson.fromJson(userStr, new TypeToken<List<ReserveItem>>() {
            }.getType());
        } catch (Exception e) {
            log.error("[对象转换] 错误, String={}", userStr);
            throw new YdException(ResultEnum.PARAM_ERROR);
        }

        return reserveItemArrayList;
    }
}